<!DOCTYPE html>
<html lang="en-us">
  <head>

    <meta http-equiv="content-type" content="text/html; charset=utf-8">
    
<meta charset="UTF-8">
<title>Get API | Elasticsearch Guide [7.7] | Elastic</title>
<link rel="home" href="index.html" title="Elasticsearch Guide [7.7]">
<link rel="up" href="docs.html" title="Document APIs">
<link rel="prev" href="docs-index_.html" title="Index API">
<link rel="next" href="docs-delete.html" title="Delete API">
<meta name="DC.type" content="Learn/Docs/Elasticsearch/Reference/7.7">
<meta name="DC.subject" content="Elasticsearch">
<meta name="DC.identifier" content="7.7">
<meta name="robots" content="noindex,nofollow">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <script src="https://cdn.optimizely.com/js/18132920325.js"></script>
    <link rel="apple-touch-icon" sizes="57x57" href="/apple-icon-57x57.png">
    <link rel="apple-touch-icon" sizes="60x60" href="/apple-icon-60x60.png">
    <link rel="apple-touch-icon" sizes="72x72" href="/apple-icon-72x72.png">
    <link rel="apple-touch-icon" sizes="76x76" href="/apple-icon-76x76.png">
    <link rel="apple-touch-icon" sizes="114x114" href="/apple-icon-114x114.png">
    <link rel="apple-touch-icon" sizes="120x120" href="/apple-icon-120x120.png">
    <link rel="apple-touch-icon" sizes="144x144" href="/apple-icon-144x144.png">
    <link rel="apple-touch-icon" sizes="152x152" href="/apple-icon-152x152.png">
    <link rel="apple-touch-icon" sizes="180x180" href="/apple-icon-180x180.png">
    <link rel="icon" type="image/png" href="/favicon-32x32.png" sizes="32x32">
    <link rel="icon" type="image/png" href="/android-chrome-192x192.png" sizes="192x192">
    <link rel="icon" type="image/png" href="/favicon-96x96.png" sizes="96x96">
    <link rel="icon" type="image/png" href="/favicon-16x16.png" sizes="16x16">
    <link rel="manifest" href="/manifest.json">
    <meta name="apple-mobile-web-app-title" content="Elastic">
    <meta name="application-name" content="Elastic">
    <meta name="msapplication-TileColor" content="#ffffff">
    <meta name="msapplication-TileImage" content="/mstile-144x144.png">
    <meta name="theme-color" content="#ffffff">
    <meta name="naver-site-verification" content="936882c1853b701b3cef3721758d80535413dbfd">
    <meta name="yandex-verification" content="d8a47e95d0972434">
    <meta name="localized" content="true">
    <meta name="st:robots" content="follow,index">
    <meta property="og:image" content="https://www.elastic.co/static/images/elastic-logo-200.png">
    <link rel="shortcut icon" href="/favicon.ico" type="image/x-icon">
    <link rel="icon" href="/favicon.ico" type="image/x-icon">
    <link rel="apple-touch-icon-precomposed" sizes="64x64" href="/favicon_64x64_16bit.png">
    <link rel="apple-touch-icon-precomposed" sizes="32x32" href="/favicon_32x32.png">
    <link rel="apple-touch-icon-precomposed" sizes="16x16" href="/favicon_16x16.png">
    <!-- Give IE8 a fighting chance -->
    <!--[if lt IE 9]>
    <script src="https://oss.maxcdn.com/html5shiv/3.7.2/html5shiv.min.js"></script>
    <script src="https://oss.maxcdn.com/respond/1.4.2/respond.min.js"></script>
    <![endif]-->
    <link rel="stylesheet" type="text/css" href="/guide/static/styles.css">
  </head>

  <!--© 2015-2021 Elasticsearch B.V. Copying, publishing and/or distributing without written permission is strictly prohibited.-->

  <body>
    <!-- Google Tag Manager -->
    <script>dataLayer = [];</script><noscript><iframe src="//www.googletagmanager.com/ns.html?id=GTM-58RLH5" height="0" width="0" style="display:none;visibility:hidden"></iframe></noscript>
    <script>(function(w,d,s,l,i){w[l]=w[l]||[];w[l].push({'gtm.start': new Date().getTime(),event:'gtm.js'});var f=d.getElementsByTagName(s)[0], j=d.createElement(s),dl=l!='dataLayer'?'&l='+l:'';j.async=true;j.src= '//www.googletagmanager.com/gtm.js?id='+i+dl;f.parentNode.insertBefore(j,f); })(window,document,'script','dataLayer','GTM-58RLH5');</script>
    <!-- End Google Tag Manager -->

    <!-- Global site tag (gtag.js) - Google Analytics -->
    <script async src="https://www.googletagmanager.com/gtag/js?id=UA-12395217-16"></script>
    <script>
      window.dataLayer = window.dataLayer || [];
      function gtag(){dataLayer.push(arguments);}
      gtag('js', new Date());
      gtag('config', 'UA-12395217-16');
    </script>

    <!--BEGIN QUALTRICS WEBSITE FEEDBACK SNIPPET-->
    <script type="text/javascript">
      (function(){var g=function(e,h,f,g){
      this.get=function(a){for(var a=a+"=",c=document.cookie.split(";"),b=0,e=c.length;b<e;b++){for(var d=c[b];" "==d.charAt(0);)d=d.substring(1,d.length);if(0==d.indexOf(a))return d.substring(a.length,d.length)}return null};
      this.set=function(a,c){var b="",b=new Date;b.setTime(b.getTime()+6048E5);b="; expires="+b.toGMTString();document.cookie=a+"="+c+b+"; path=/; "};
      this.check=function(){var a=this.get(f);if(a)a=a.split(":");else if(100!=e)"v"==h&&(e=Math.random()>=e/100?0:100),a=[h,e,0],this.set(f,a.join(":"));else return!0;var c=a[1];if(100==c)return!0;switch(a[0]){case "v":return!1;case "r":return c=a[2]%Math.floor(100/c),a[2]++,this.set(f,a.join(":")),!c}return!0};
      this.go=function(){if(this.check()){var a=document.createElement("script");a.type="text/javascript";a.src=g;document.body&&document.body.appendChild(a)}};
      this.start=function(){var a=this;window.addEventListener?window.addEventListener("load",function(){a.go()},!1):window.attachEvent&&window.attachEvent("onload",function(){a.go()})}};
      try{(new g(100,"r","QSI_S_ZN_emkP0oSe9Qrn7kF","https://znemkp0ose9qrn7kf-elastic.siteintercept.qualtrics.com/WRSiteInterceptEngine/?Q_ZID=ZN_emkP0oSe9Qrn7kF")).start()}catch(i){}})();
    </script><div id="ZN_emkP0oSe9Qrn7kF"><!--DO NOT REMOVE-CONTENTS PLACED HERE--></div>
    <!--END WEBSITE FEEDBACK SNIPPET-->

    <div id="elastic-nav" style="display:none;"></div>
    <script src="https://www.elastic.co/elastic-nav.js"></script>

    <!-- Subnav -->
    <div>
      <div>
        <div class="tertiary-nav d-none d-md-block">
          <div class="container">
            <div class="p-t-b-15 d-flex justify-content-between nav-container">
              <div class="breadcrum-wrapper"><span><a href="/guide/" style="font-size: 14px; font-weight: 600; color: #000;">Docs</a></span></div>
            </div>
          </div>
        </div>
      </div>
    </div>

    <div class="main-container">
      <section id="content">
        <div class="content-wrapper">

          <section id="guide" lang="en">
            <div class="container">
              <div class="row">
                <div class="col-xs-12 col-sm-8 col-md-8 guide-section">
                  <!-- start body -->
                  <div class="page_header">
<strong>IMPORTANT</strong>: No additional bug fixes or documentation updates
will be released for this version. For the latest information, see the
<a href="../current/index.html">current release documentation</a>.
</div>
<div id="content">
<div class="breadcrumbs">
<span class="breadcrumb-link"><a href="index.html">Elasticsearch Guide [7.7]</a></span>
»
<span class="breadcrumb-link"><a href="rest-apis.html">REST APIs</a></span>
»
<span class="breadcrumb-link"><a href="docs.html">Document APIs</a></span>
»
<span class="breadcrumb-node">Get API</span>
</div>
<div class="navheader">
<span class="prev">
<a href="docs-index_.html">« Index API</a>
</span>
<span class="next">
<a href="docs-delete.html">Delete API »</a>
</span>
</div>
<div class="section">
<div class="titlepage"><div><div>
<h2 class="title">
<a id="docs-get"></a>Get API<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h2>
</div></div></div>

<p>Retrieves the specified JSON document from an index.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET twitter/_doc/0</pre>
</div>
<div class="console_widget" data-snippet="snippets/1459.console"></div>
<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-get-api-request"></a>Request<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h3>
</div></div></div>
<p><code class="literal">GET &lt;index&gt;/_doc/&lt;_id&gt;</code></p>
<p><code class="literal">HEAD &lt;index&gt;/_doc/&lt;_id&gt;</code></p>
<p><code class="literal">GET &lt;index&gt;/_source/&lt;_id&gt;</code></p>
<p><code class="literal">HEAD &lt;index&gt;/_source/&lt;_id&gt;</code></p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-get-api-desc"></a>Description<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h3>
</div></div></div>
<p>You use GET to retrieve a document and its source or stored fields from a
particular index. Use HEAD to verify that a document exists. You can
use the <code class="literal">_source</code> resource retrieve just the document source or verify
that it exists.</p>
<h5>
<a id="realtime"></a>Realtime<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h5>
<p>By default, the get API is realtime, and is not affected by the refresh
rate of the index (when data will become visible for search). In case where
stored fields are requested (see <code class="literal">stored_fields</code> parameter) and the document
has been updated but is not yet refreshed, the get API will have to parse
and analyze the source to extract the stored fields. In order to disable
realtime GET, the <code class="literal">realtime</code> parameter can be set to <code class="literal">false</code>.</p>
<h5>
<a id="get-source-filtering"></a>Source filtering<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h5>
<p>By default, the get operation returns the contents of the <code class="literal">_source</code> field unless
you have used the <code class="literal">stored_fields</code> parameter or if the <code class="literal">_source</code> field is disabled.
You can turn off <code class="literal">_source</code> retrieval by using the <code class="literal">_source</code> parameter:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET twitter/_doc/0?_source=false</pre>
</div>
<div class="console_widget" data-snippet="snippets/1460.console"></div>
<p>If you only need one or two fields from the <code class="literal">_source</code>, use the <code class="literal">_source_includes</code>
or <code class="literal">_source_excludes</code> parameters to include or filter out particular fields.
This can be especially helpful with large documents where partial retrieval can
save on network overhead. Both parameters take a comma separated list
of fields or wildcard expressions. Example:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET twitter/_doc/0?_source_includes=*.id&amp;_source_excludes=entities</pre>
</div>
<div class="console_widget" data-snippet="snippets/1461.console"></div>
<p>If you only want to specify includes, you can use a shorter notation:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET twitter/_doc/0?_source=*.id,retweeted</pre>
</div>
<div class="console_widget" data-snippet="snippets/1462.console"></div>
<h5>
<a id="get-routing"></a>Routing<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h5>
<p>If routing is used during indexing, the routing value also needs to be
specified to retrieve a document. For example:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET twitter/_doc/2?routing=user1</pre>
</div>
<div class="console_widget" data-snippet="snippets/1463.console"></div>
<p>This request gets the tweet with id <code class="literal">2</code>, but it is routed based on the
user. The document is not fetched if the correct routing is not specified.</p>
<h5>
<a id="preference"></a>Preference<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h5>
<p>Controls a <code class="literal">preference</code> of which shard replicas to execute the get
request on. By default, the operation is randomized between the shard
replicas.</p>
<p>The <code class="literal">preference</code> can be set to:</p>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">_local</code>
</span>
</dt>
<dd>
The operation will prefer to be executed on a local
allocated shard if possible.
</dd>
<dt>
<span class="term">
Custom (string) value
</span>
</dt>
<dd>
A custom value will be used to guarantee that
the same shards will be used for the same custom value. This can help
with "jumping values" when hitting different shards in different refresh
states. A sample value can be something like the web session id, or the
user name.
</dd>
</dl>
</div>
<h5>
<a id="get-refresh"></a>Refresh<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h5>
<p>The <code class="literal">refresh</code> parameter can be set to <code class="literal">true</code> in order to refresh the
relevant shard before the get operation and make it searchable. Setting
it to <code class="literal">true</code> should be done after careful thought and verification that
this does not cause a heavy load on the system (and slows down
indexing).</p>
<h5>
<a id="get-distributed"></a>Distributed<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h5>
<p>The get operation gets hashed into a specific shard id. It then gets
redirected to one of the replicas within that shard id and returns the
result. The replicas are the primary shard and its replicas within that
shard id group. This means that the more replicas we have, the
better GET scaling we will have.</p>
<h5>
<a id="get-versioning"></a>Versioning support<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h5>
<p>You can use the <code class="literal">version</code> parameter to retrieve the document only if
its current version is equal to the specified one.</p>
<p>Internally, Elasticsearch has marked the old document as deleted and added an
entirely new document. The old version of the document doesn’t disappear
immediately, although you won’t be able to access it. Elasticsearch cleans up
deleted documents in the background as you continue to index more data.</p>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-get-api-path-params"></a>Path parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">&lt;index&gt;</code>
</span>
</dt>
<dd>
(Required, string) Name of the index that contains the document.
</dd>
<dt>
<span class="term">
<code class="literal">&lt;_id&gt;</code>
</span>
</dt>
<dd>
(Required, string) Unique identifier of the document.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-get-api-query-params"></a>Query parameters<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">preference</code>
</span>
</dt>
<dd>
(Optional, string) Specifies the node or shard the operation should be
performed on. Random by default.
</dd>
<dt>
<span class="term">
<code class="literal">realtime</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, the request is real-time as opposed to near-real-time.
Defaults to <code class="literal">true</code>. See <a class="xref" href="docs-get.html#realtime" title="Realtime">Realtime</a>.
</dd>
<dt>
<span class="term">
<code class="literal">refresh</code>
</span>
</dt>
<dd>
(Optional, Boolean) If <code class="literal">true</code>, the request refreshes the relevant shard before
retrieving the document. Defaults to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">routing</code>
</span>
</dt>
<dd>
(Optional, string) Target the specified primary shard.
</dd>
<dt>
<span class="term">
<code class="literal">stored_fields</code>
</span>
</dt>
<dd>
(Optional, boolean) If <code class="literal">true</code>, retrieves the document fields stored in the
index rather than the document <code class="literal">_source</code>. Defaults to <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">_source</code>
</span>
</dt>
<dd>
(Optional, string) True or false to return the <code class="literal">_source</code> field or not, or a
list of fields to return.
</dd>
<dt>
<span class="term">
<code class="literal">_source_excludes</code>
</span>
</dt>
<dd>
<p>
(Optional, string)
A comma-separated list of <a class="xref" href="mapping-source-field.html" title="_source field">source fields</a> to exclude from
the response.
</p>
<p>You can also use this parameter to exclude fields from the subset specified in
<code class="literal">_source_includes</code> query parameter.</p>
<p>If the <code class="literal">_source</code> parameter is <code class="literal">false</code>, this parameter is ignored.</p>
</dd>
<dt>
<span class="term">
<code class="literal">_source_includes</code>
</span>
</dt>
<dd>
<p>
(Optional, string)
A comma-separated list of <a class="xref" href="mapping-source-field.html" title="_source field">source fields</a> to
include in the response.
</p>
<p>If this parameter is specified, only these source fields are returned. You can
exclude fields from this subset using the <code class="literal">_source_excludes</code> query parameter.</p>
<p>If the <code class="literal">_source</code> parameter is <code class="literal">false</code>, this parameter is ignored.</p>
</dd>
<dt>
<span class="term">
<code class="literal">version</code>
</span>
</dt>
<dd>
(Optional, integer) Explicit version number for concurrency control.
The specified version must match the current version of the document for the
request to succeed.
</dd>
<dt>
<span class="term">
<code class="literal">version_type</code>
</span>
</dt>
<dd>
(Optional, enum) Specific version type: <code class="literal">internal</code>, <code class="literal">external</code>,
<code class="literal">external_gte</code>.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-get-api-response-body"></a>Response body<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h3>
</div></div></div>
<div class="variablelist">
<dl class="variablelist">
<dt>
<span class="term">
<code class="literal">_index</code>
</span>
</dt>
<dd>
The name of the index the document belongs to.
</dd>
<dt>
<span class="term">
<code class="literal">_type</code>
</span>
</dt>
<dd>
The document type. Elasticsearch indices now support a single document type, <code class="literal">_doc</code>.
</dd>
<dt>
<span class="term">
<code class="literal">_id</code>
</span>
</dt>
<dd>
The unique identifier for the document.
</dd>
<dt>
<span class="term">
<code class="literal">_version</code>
</span>
</dt>
<dd>
The document version. Incremented each time the document is updated.
</dd>
<dt>
<span class="term">
<code class="literal">_seq_no</code>
</span>
</dt>
<dd>
The sequence number assigned to the document for the indexing
operation. Sequence numbers are used to ensure an older version of a document
doesn’t overwrite a newer version. See <a class="xref" href="docs-index_.html#optimistic-concurrency-control-index" title="Optimistic concurrency control">Optimistic concurrency control</a>.
</dd>
<dt>
<span class="term">
<code class="literal">_primary_term</code>
</span>
</dt>
<dd>
The primary term assigned to the document for the indexing operation.
See <a class="xref" href="docs-index_.html#optimistic-concurrency-control-index" title="Optimistic concurrency control">Optimistic concurrency control</a>.
</dd>
<dt>
<span class="term">
<code class="literal">found</code>
</span>
</dt>
<dd>
Indicates whether the document exists: <code class="literal">true</code> or <code class="literal">false</code>.
</dd>
<dt>
<span class="term">
<code class="literal">_routing</code>
</span>
</dt>
<dd>
The explicit routing, if set.
</dd>
<dt>
<span class="term">
<em>_source</em>
</span>
</dt>
<dd>
If <code class="literal">found</code> is <code class="literal">true</code>, contains the document data formatted in JSON.
Excluded if the <code class="literal">_source</code> parameter is set to <code class="literal">false</code> or the <code class="literal">stored_fields</code>
parameter is set to <code class="literal">true</code>.
</dd>
<dt>
<span class="term">
<em>_fields</em>
</span>
</dt>
<dd>
If the <code class="literal">stored_fields</code> parameter is set to <code class="literal">true</code> and <code class="literal">found</code> is
<code class="literal">true</code>, contains the document fields stored in the index.
</dd>
</dl>
</div>
</div>

<div class="section">
<div class="titlepage"><div><div>
<h3 class="title">
<a id="docs-get-api-example"></a>Examples<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h3>
</div></div></div>
<p>Retrieve the JSON document with the <code class="literal">_id</code> 0 from the <code class="literal">twitter</code> index:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET twitter/_doc/0</pre>
</div>
<div class="console_widget" data-snippet="snippets/1464.console"></div>
<p>The API returns the following result:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
    "_index" : "twitter",
    "_type" : "_doc",
    "_id" : "0",
    "_version" : 1,
    "_seq_no" : 10,
    "_primary_term" : 1,
    "found": true,
    "_source" : {
        "user" : "kimchy",
        "date" : "2009-11-15T14:12:12",
        "likes": 0,
        "message" : "trying out Elasticsearch"
    }
}</pre>
</div>
<p>Check to see if a document with the <code class="literal">_id</code> 0 exists:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">HEAD twitter/_doc/0</pre>
</div>
<div class="console_widget" data-snippet="snippets/1465.console"></div>
<p>Elasticsearch returns a status code of <code class="literal">200 - OK</code> if the document exists, or
<code class="literal">404 - Not Found</code> if it doesn’t.</p>
<h5>
<a id="_source"></a>Get the source field only<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h5>
<p>Use the <code class="literal">&lt;index&gt;/_source/&lt;id&gt;</code> resource to get
just the <code class="literal">_source</code> field of a document. For example:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET twitter/_source/1</pre>
</div>
<div class="console_widget" data-snippet="snippets/1466.console"></div>
<p>You can use the source filtering parameters to control which parts of the
<code class="literal">_source</code> are returned:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET twitter/_source/1/?_source_includes=*.id&amp;_source_excludes=entities</pre>
</div>
<div class="console_widget" data-snippet="snippets/1467.console"></div>
<p>You can use HEAD with the <code class="literal">_source</code> endpoint to efficiently
test whether or not the document _source exists. A document’s source is not
available if it is disabled in the <a class="xref" href="mapping-source-field.html" title="_source field">mapping</a>.</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">HEAD twitter/_source/1</pre>
</div>
<div class="console_widget" data-snippet="snippets/1468.console"></div>
<h5>
<a id="get-stored-fields"></a>Get stored fields<a class="edit_me edit_me_private" rel="nofollow" title="Editing on GitHub is available to Elastic" href="https://github.com/elastic/elasticsearch/edit/7.7/docs/reference/docs/get.asciidoc">edit</a>
</h5>
<p>Use the <code class="literal">stored_fields</code> parameter to specify the set of stored fields you want
to retrieve. Any requested fields that are not stored are ignored.
Consider for instance the following mapping:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT twitter
{
   "mappings": {
       "properties": {
          "counter": {
             "type": "integer",
             "store": false
          },
          "tags": {
             "type": "keyword",
             "store": true
          }
       }
   }
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1469.console"></div>
<p>Now we can add a document:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT twitter/_doc/1
{
    "counter" : 1,
    "tags" : ["red"]
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1470.console"></div>
<p>And then try to retrieve it:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET twitter/_doc/1?stored_fields=tags,counter</pre>
</div>
<div class="console_widget" data-snippet="snippets/1471.console"></div>
<p>The API returns the following result:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
   "_index": "twitter",
   "_type": "_doc",
   "_id": "1",
   "_version": 1,
   "_seq_no" : 22,
   "_primary_term" : 1,
   "found": true,
   "fields": {
      "tags": [
         "red"
      ]
   }
}</pre>
</div>
<p>Field values fetched from the document itself are always returned as an array.
Since the <code class="literal">counter</code> field is not stored, the get request  ignores it.</p>
<p>You can also retrieve metadata fields like the <code class="literal">_routing</code> field:</p>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">PUT twitter/_doc/2?routing=user1
{
    "counter" : 1,
    "tags" : ["white"]
}</pre>
</div>
<div class="console_widget" data-snippet="snippets/1472.console"></div>
<div class="pre_wrapper lang-console">
<pre class="programlisting prettyprint lang-console">GET twitter/_doc/2?routing=user1&amp;stored_fields=tags,counter</pre>
</div>
<div class="console_widget" data-snippet="snippets/1473.console"></div>
<p>The API returns the following result:</p>
<div class="pre_wrapper lang-console-result">
<pre class="programlisting prettyprint lang-console-result">{
   "_index": "twitter",
   "_type": "_doc",
   "_id": "2",
   "_version": 1,
   "_seq_no" : 13,
   "_primary_term" : 1,
   "_routing": "user1",
   "found": true,
   "fields": {
      "tags": [
         "white"
      ]
   }
}</pre>
</div>
<p>Only leaf fields can be retrieved with the <code class="literal">stored_field</code> option. Object fields
can’t be returned—​if specified, the request fails.</p>
</div>

</div>
<div class="navfooter">
<span class="prev">
<a href="docs-index_.html">« Index API</a>
</span>
<span class="next">
<a href="docs-delete.html">Delete API »</a>
</span>
</div>
</div>

                  <!-- end body -->
                </div>
                <div class="col-xs-12 col-sm-4 col-md-4" id="right_col">
                  <div id="rtpcontainer" style="display: block;">
                    <div class="mktg-promo">
                      <h3>Most Popular</h3>
                      <ul class="icons">
                        <li class="icon-elasticsearch-white"><a href="https://www.elastic.co/webinars/getting-started-elasticsearch?baymax=default&amp;elektra=docs&amp;storm=top-video">Get Started with Elasticsearch: Video</a></li>
                        <li class="icon-kibana-white"><a href="https://www.elastic.co/webinars/getting-started-kibana?baymax=default&amp;elektra=docs&amp;storm=top-video">Intro to Kibana: Video</a></li>
                        <li class="icon-logstash-white"><a href="https://www.elastic.co/webinars/introduction-elk-stack?baymax=default&amp;elektra=docs&amp;storm=top-video">ELK for Logs &amp; Metrics: Video</a></li>
                      </ul>
                    </div>
                  </div>
                </div>
              </div>
            </div>
          </section>

        </div>


<div id="elastic-footer"></div>
<script src="https://www.elastic.co/elastic-footer.js"></script>
<!-- Footer Section end-->

      </section>
    </div>

<script src="/guide/static/jquery.js"></script>
<script type="text/javascript" src="/guide/static/docs.js"></script>
<script type="text/javascript">
  window.initial_state = {}</script>
  </body>
</html>
